<?php
declare (strict_types = 1);

namespace app\admin\controller;

use addons\Builder\facade\Builder;
use app\common\tool\Result;
use think\App;
use think\Response;
use think\response\Json;
use think\facade\View;
//该文件为自动生成，请按需修改
class Refund extends Base
{
    //主键，默认为id
    protected string $pk = 'id';

    //主模型
    protected string $model = '\app\common\model\Refund';
    
    protected $hasOne = ['user', 'express','order'];


    public function index(): string
    {
       return Builder::Table()
           ->autoStructure($this->model, $this->pk, 'barDemo,200')
           ->addRightButtons(['edit' => ['title' => '查看', 'unity_title' => '审核/查看', 'size' => '60%']])
           ->addSearch([
               ['uid', '会员编号/昵称/手机号', 'input', '', '\app\common\model\User', 'code|nickname|mobile,id'],
               ['order_id', '退款订单号', 'input', '', '\app\common\model\Order', 'sn,id'],
               ['status',  '退款状态', 'select', self::getStatusList()],
               ['type',  '退款类型', 'select', self::getTypeList()],
           ])
           ->fetch();
    }
    /**
     * 退款状态
     */
    public static function getStatusList()
    {
        return [
            1 => '待审核',
            2 => '同意退款',
            3 => '待寄回',
            4 => '拒绝退款',
            5 => '退款成功'
        ];
    }
    /**
     * 退款类型
     */
    public static function getTypeList()
    {
        return [
            1 => '仅退款',
            2 => '退货退款'
        ];
    }
    public function edit($id = '', $tpl = 'refund/edit', $info = ''): string
    {
        View::assign([
            'express' => \app\common\model\Express::where(['status' => 1])->select(),
        ]);
        return parent::edit($id, $tpl, $info); // TODO: Change the autogenerated stub
    }

    public function save($param = [], $model = true): Json
    {
        return parent::save($param, $model); // TODO: Change the autogenerated stub
    }
}
